﻿using System.Windows.Media;

namespace AutoRevit.Ribbon.Ribbon.Mapper;

/// <summary>
/// SplitButton控件映射器
/// </summary>
public class SplitButtonMapper : ControlItemMapper
{
    /// <summary>
    /// 
    /// </summary>
    /// <param name="name"></param>
    /// <param name="text"></param>
    public SplitButtonMapper(string name, string text) : base(name)
    {
        Text = text;
    }

    /// <summary>
    /// 获取当前SplitButtonMapper下的PushButtonMapper
    /// </summary>
    /// <param name="pushButtonName"></param>
    /// <returns></returns>
    public PushButtonMapper? this[string pushButtonName]
    {
        get
        {
            return Items.FirstOrDefault(t => t.Name == pushButtonName);
        }
    }

    /// <summary>
    /// 
    /// </summary>
    public string Text { get; set; } = null!;

    /// <summary>
    /// 
    /// </summary>
    public ImageSource Image { get; set; } = null!;

    /// <summary>
    /// 
    /// </summary>
    public ImageSource LargeImage { get; set; } = null!;

    /// <summary>
    /// 
    /// </summary>
    public List<PushButtonMapper> Items { get; set; } = [];

    /// <summary>
    /// 
    /// </summary>
    public string CurrentButtonName { get; set; } = null!;

    /// <summary>
    /// 
    /// </summary>
    public bool IsSynchronizedWithCurrentItem { get; set; } = true;

    /// <summary>
    /// 实际已生成的控件
    /// </summary>
    public SplitButton? Control { get; internal set; }

    /// <summary>
    /// 
    /// </summary>
    /// <returns></returns>
    public SplitButtonData GetData()
    {
        var data = new SplitButtonData(Name, Text)
        {
            ToolTip = ToolTip,
            LongDescription = LongDescription,
            Image = Image,
            ToolTipImage = ToolTipImage,
            LargeImage = LargeImage,
        };

        data.SetContextualHelp(GetContextualHelp());
        return data;
    }
}
